<?php
$week_array = BUtils::WeekDayKeys(7, true);
$now_ts = time();
$default_logo = Yii::app()->baseUrl . '/img/default_special_thumb.png';
foreach ($rows as $r) {
	//set offer picture
	$url_thumb_default = Yii::app()->baseUrl . '/img/default_special_thumb.png';
	$url_picture_default = Yii::app()->baseUrl . '/img/default_special_picture.png';
	$url_thumb = empty($r['url_picture']) ? $r['url_offer_img'] : $r['url_picture'];
	if (!empty($url_thumb)) {
		$url_thumb = BUtils::GetOfferPictureUrl($url_thumb);
		$url_picture = str_replace('thumb_', '', $url_thumb);
	} else {
		$url_thumb = $url_thumb_default;
		$url_picture = $url_picture_default;
	}
	
	//set the day string
	$week_string = BUtils::GetWeekdays($r['week_days'], $week_array);
	$range_date = BUtils::GetRecentDayName($r['week_days'], $week_string, false, $r['start_hour']);
	$period_string = BUtils::GetUntilDate($r['uts_end_date']);

	//set the valid_time
	$range_time = BUtils::GetHourRangeFormat($r['start_hour'], $r['end_hour'], $r['show_hours']);
	
	//set price, discount or highlight
	$highlight = $del_price = '';
	if (!empty($r['price'])) {
		$highlight = MerchantObject::formatPrice($r['price']);
		if (!empty($r['value'])) {
			$del_price = '<span class="oldprice label">€'.$r['value'].'</span>';
		}
	} elseif (!empty($r['discount'])) {
		$highlight = MerchantObject::formatDiscount($r['discount']);
	}
	
	//business icon url
	$biz_icon = Yii::app()->baseUrl . '/img/icons/icon_others.png';
	if (!empty($r['category_key'])) {
		$biz_icon = Yii::app()->baseUrl . '/img/icons/icon_'.$r['category_key'].'.png';
	}
	
	//offer content
	$content = strip_tags(trim($r['content']));
	
	//offer view link
	$offer_link = Yii::app()->createUrl('/special/view', array('id' => $r['id']));
?>
<div class="mb_offer special_line">
	<div class="mb_picture">
		<a class="popup-offer" href="<?php echo $offer_link; ?>"><img src="<?php echo $url_thumb; ?>" onError="this.onerror=null;this.src='<?php echo $default_logo; ?>';" alt="" /></a>
	</div>
	<div class="mb_price">
		<div class="highlight"><?php echo $highlight; ?></div>
		<?php echo $del_price; ?>
	</div>
	<div class="mb_period">
		<div class="time"><?php echo $range_time; ?></div>
		<div class="date"><?php echo $range_date; ?></div>
		<?php echo $period_string; ?>
	</div>
	<div class="clearfix"></div>
	<div>
		<div class="mb_text"><?php echo $content; ?></div>
	</div>
</div>
<?php } ?>
<script>
$(function() {
	$('.mb_offer').click(function(ev){
		ev.preventDefault();
		var url = $(this).find('.popup-offer').attr('href');
		$.colorbox({href:url, transition:'none'});
	});
});
</script>